$(function() {
	$.divselect("#divselect_po_formate", "#formate");
	
});

//添加明细弹窗
var toAddOrderDetail = function(){
	$.box('.onlyuserforaddtaskalertbox', {
		onOpen : function() {
			$('#scrollbar').tinyscrollbar();
			$('#scrollbar_002').tinyscrollbar();//里面有2个滚动条*/			
		}
	}, {
		submit:{
			close:false,
			dom:['#submitOrderDetail'],
			fun:function(index){
				var currObj = this;
				addOrderDetail(function(){					
					currObj.close(index);
				});
				
			}
		},
		close : {
			dom : [ '.onlyuserforaddtaskalertbox .closeforaddtask','.onlyuserforaddtaskalertbox .c_but_no' ]
		}
	});
	
};

//添加明细
var addOrderDetail = function(callback){
	validate();//验证
	var fun = function(msg) {
		if (msg.result == "success") {
			if(callback){
				callback();
			}
			layer.msg("新建稿件成功！",1,9,function(){
				window.location.href=globePath+"/ordermanage/toAddOrderDetail."+action+"?orderId="+$("#orderId").val();
			});
		} else {
			layer.alert(msg.result);
		};
	};
	
	ajaxCommFunWithDataType(globePath+"/ordermanage/submitPOrderDetail"+action, $("#addOrderDetailForm").serialize(),'json',fun);
};
//验证
var validate = function(){
	var detailName = $.trim($("#detailName").val());
	if(detailName==''){
		layer.msg("稿件名不能为空");
		return false;
	}
	var count = $.trim($("#count").val());
	if(count==''){
		layer.msg("数量不能为空");
		return false;
	}
	 
	var unit = $.trim($("#unit").val());
	if(unit==''){
		layer.msg("单位不能为空");
		return false;
	}
};

//删除明细
var deleteDetail = function(id){
	if(window.confirm("确定要删除该明细？")){
		var fun = function(msg) {
			if (msg.result == "success") {
				layer.msg("删除明细成功！",1,9,function(){
					window.location.href=globePath+"/ordermanage/toAddOrderDetail."+action+"?orderId="+$("#orderId").val();
				});
			} else {
				layer.alert(msg.result);
			};
		};
		
		ajaxCommFunWithDataType(globePath+"/ordermanage/deleteOrderDetail"+action, "orderDetailId="+id,'json',fun);
	}
};